package com.xjtu.controller.admin;

import com.xjtu.dto.MedicalVisitDto;
import com.xjtu.result.PageResult;
import com.xjtu.result.Result;
import com.xjtu.service.MedicalVisitService;
import com.xjtu.vo.GetMedicalVisitByIdVo;
import com.xjtu.vo.MedicalVisitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/admin/medicalVisit")
@Slf4j
@Api(tags = "就诊记录接口")
public class MedicalVisitController {

    @Autowired
    MedicalVisitService medicalVisitService;
    @PostMapping
    @ApiOperation("新增就诊记录")
    public Result addMedicalVisit(@RequestBody @Valid MedicalVisitDto medicalVisitDto){
        medicalVisitService.insert(medicalVisitDto);
        System.out.println(medicalVisitDto.getVisitTime());
        return Result.success();
    }

    @GetMapping()
    @ApiOperation(("查询某次就诊的详情信息"))
    public Result<GetMedicalVisitByIdVo> getMedicalVisitById(@RequestParam Long visitId){
        log.info("传入的id为{}",visitId);
        GetMedicalVisitByIdVo getMedicalVisitByIdVo = medicalVisitService.queryByVisitId(visitId);
        return Result.success(getMedicalVisitByIdVo);
    }

    @DeleteMapping("/{visitId}")
    @ApiOperation("根据id删除某条记录")
    public Result deleteVisitById(@PathVariable Long visitId){
        medicalVisitService.deleteVisitById(visitId);
        return Result.success();
    }

    @GetMapping("/lists")
    @ApiOperation("获取就诊记录列表")
    public Result<PageResult> getMedicalVisitList(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                  @RequestParam(required = false, defaultValue = "10")Integer perPage,
                                                  @RequestParam(required = false, defaultValue = "null") String elderlyName) {
        PageResult pageResult = medicalVisitService.queryAll(page, perPage, elderlyName);
        return Result.success(pageResult);
    }
}
